package com.ztk.threadbasic.synchronizeds;

public class Synchronized01 {

    private String desc = "desc_0";

    public static void main(String[] args) throws InterruptedException {
        Synchronized01 synchronized01 = new Synchronized01();
        Thread desc_011 = new Thread(() -> System.out.println(synchronized01.getDesc("desc_01", 1)));
        Thread desc_02 = new Thread(() -> System.out.println(synchronized01.getDesc("desc_02", 2)));
        desc_011.start();
        desc_02.start();
        System.out.println("结束");
    }

    private synchronized String getDesc(String old_desc, int flag) {
        try {
            Thread.sleep(3 * 1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(flag);
        desc = old_desc;
        return desc;
    }
}
